﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Shell;

namespace AudioDemo
{
    /// <summary>
    /// media1.xaml 的交互逻辑
    /// </summary>
    public partial class media1 : Window
    {
        public media1()
        {
            InitializeComponent();
        }

//选择视频文件
private void openBtn_Click(object sender, RoutedEventArgs e)
{
    CommonOpenFileDialog open = new CommonOpenFileDialog();
    open.EnsureReadOnly = true;
    open.Filters.Add(new CommonFileDialogFilter("Mp4文件", "*.mp4"));
    open.Filters.Add(new CommonFileDialogFilter("Wmv文件", "*.wmv"));
    open.Filters.Add(new CommonFileDialogFilter("Avi文件", "*.avi"));
    open.Filters.Add(new CommonFileDialogFilter("Mp3文件", "*.mp3"));
    if (open.ShowDialog() == CommonFileDialogResult.Ok)
    {
        //指定媒体文件地址
        mediaElement.Source = new Uri(open.FileName, UriKind.Relative);
        playBtn.IsEnabled = true;
    }
}
//开始播放
private void playBtn_Click(object sender, RoutedEventArgs e)
{
    mediaElement.Play();
    mediaElement.ToolTip = "开始播放";
}
//停止播放
private void stopBtn_Click(object sender, RoutedEventArgs e)
{
    mediaElement.Pause();
    mediaElement.ToolTip = "停止播放";
}

//后退
private void backBtn_Click(object sender, RoutedEventArgs e)
{
    mediaElement.Position = mediaElement.Position - TimeSpan.FromSeconds(10);
}
//前进
private void forwardBtn_Click(object sender, RoutedEventArgs e)
{
    mediaElement.Position = mediaElement.Position +TimeSpan.FromSeconds(10);
}

    }
}
